﻿using Hopscotch.Common.Contracts.AppService;
using Hopscotch.Common.Contracts.EnqService;
using Hopscotch.Domain.Finance;
using Hopscotch.Presentation.Common;
using Hopscotch.Presentation.Common.Threading;
using Hopscotch.Presentation.Controls.DataProviders;
using Hopscotch.Presentation.TradeModule.ViewModels;
using Hopscotch.Test.Presentation.Threading;
using Microsoft.Practices.Prism.PubSubEvents;
using Moq;
using NUnit.Framework;
using FluentAssertions;
using Hopscotch.Domain.Enquiry;

namespace Hopscotch.Presentation.TradeModule.Test
{
    [TestFixture]
    public class TradeViewModelTest
    {
        private TradeViewModel tradeViewModel;

        [SetUp]
        public void SetUp()
        {
            IEventAggregator eventAggregator = new EventAggregator();
            IDispatcher dispatcher = new SynchronousDispatcher();

            Mock<IShellContext> workspaceContext = new Mock<IShellContext>();
            Mock<ITradeService> tradeService = new Mock<ITradeService>();
            Mock<ITradeEnqService> tradeHubClient = new Mock<ITradeEnqService>();
            Mock<IInstrumentDataProvider> instrumentDataProvider = new Mock<IInstrumentDataProvider>();
            Mock<IPriceControlDataProvider> priceControlDataProvider = new Mock<IPriceControlDataProvider>();

            tradeViewModel = new TradeViewModel(
                    eventAggregator,
                    dispatcher,
                    workspaceContext.Object,
                    tradeService.Object ,
                    tradeHubClient.Object,
                    instrumentDataProvider.Object,
                    priceControlDataProvider.Object);
        }

        [Test]
        public void TestSettingNullInstrumentSetsInstrumentIdToNull()
        {
            var trade = new Trade();
            trade.InstrumentId = 42;
            trade.Instrument = new EquityInstrument() { Id = 42 };
            tradeViewModel.SetModel(trade);

            tradeViewModel.Instrument = null;
            trade.InstrumentId.Should().NotHaveValue();
        }

    }
}
